package kotan.view;

import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;

import kotan.AppEngineEnv;
import kotan.Kotan;

/**
 * Dialog to setup environment
 * @author shuji.w6e
 * @since 1.0
 */
public class StartupDialog {

    public static void showDialog(AppEngineEnv env) {
        final JDialog dialog = new JDialog();
        dialog.setModal(true);
        dialog.setTitle("Setup AppEngine environment.");
        dialog.setMinimumSize(new Dimension(600, 400));
        dialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                // default close button
                System.out.println("windowClosing: " + e);
                Kotan.get().shutdown();
                System.exit(0);
            }
        });
        @SuppressWarnings("serial")
        final StartupPanel panel = new StartupPanel() {

            @Override
            protected void onStart() {
                super.onStart();
                dialog.dispose();
            }

            @Override
            protected void onCancel() {
                super.onCancel();
            }
        };
        panel.setAppEngineEnv(env);
        dialog.add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
    }
}
